/*
编写 : Hexh
时间 : 2012-5-7 10:29:53
*/
using System;
using System.Collections.Generic;
using HMIS.FrameWork.DomainBase;
using HMIS.FrameWork.Repository;
using HMIS.FrameWork.Repository.Nhb;
using FsCarInfo;

namespace FsCarInfo.Core.Entity.IRespositories.Impl
{
	/// <summary>
	///	 the repository of FsBcar
	/// </summary>
	public class FsBcarRepositoryImpl : RepositoryNhbImpl<FsBcar>, IFsBcarRepository
	{

		public bool IsFieldExist(string fieldName, string fieldValue, string id)
		{
			return base.IsFieldExist(fieldName, fieldValue, id, null);
		}
	
		/// <summary>
		/// </summary>
		public IList<FsBcar> GetPlist(int start, int limit, string sort, string dir, List<DataFilter> filters, out long total)
		{
			// filter
			var strFilter = base.GetHqlstrByExtFilter(filters, "t");
			
			// sort
			string strSort = string.IsNullOrEmpty(sort) ? string.Empty : " order by t." + sort + " " + dir;

			// sql条件
			string strSql = @" from FsBcar as t "
				+ (string.IsNullOrEmpty(strFilter) ? string.Empty : " where " + strFilter);

			// 查询
			var query = Session.CreateQuery(@"select t " + strSql + strSort);
			if (limit > 0)
				query.SetFirstResult(start).SetMaxResults(limit);

			// 汇总
			total = Session.CreateQuery(@"select count(*) " + strSql)
				.UniqueResult<long>();
			
			return query.List<FsBcar>();
		}
	}
}
